/* Automatically generated by mkrunetype.awk */
#include <stdlib.h>

#include "../utf.h"
#include "runetype.h"

static Rune lower4[][2] = {
	{ 0x0101, 0x012F },
	{ 0x0133, 0x0137 },
	{ 0x013A, 0x0148 },
	{ 0x014B, 0x0177 },
	{ 0x017A, 0x017E },
	{ 0x0183, 0x0185 },
	{ 0x01A1, 0x01A5 },
	{ 0x01B4, 0x01B6 },
	{ 0x01CE, 0x01DC },
	{ 0x01DF, 0x01EF },
	{ 0x01F9, 0x021F },
	{ 0x0223, 0x0233 },
	{ 0x0247, 0x024F },
	{ 0x0371, 0x0373 },
	{ 0x03D9, 0x03EF },
	{ 0x0461, 0x0481 },
	{ 0x048B, 0x04BF },
	{ 0x04C2, 0x04CE },
	{ 0x04D1, 0x052F },
	{ 0x1E01, 0x1E95 },
	{ 0x1EA1, 0x1EFF },
	{ 0x2C68, 0x2C6C },
	{ 0x2C81, 0x2CE3 },
	{ 0x2CEC, 0x2CEE },
	{ 0xA641, 0xA66D },
	{ 0xA681, 0xA69B },
	{ 0xA723, 0xA72F },
	{ 0xA733, 0xA76F },
	{ 0xA77A, 0xA77C },
	{ 0xA77F, 0xA787 },
	{ 0xA791, 0xA793 },
	{ 0xA797, 0xA7A9 },
};

static Rune lower2[][3] = {
	{ 0x0061, 0x007A, 0x0041 },
	{ 0x00E0, 0x00F6, 0x00C0 },
	{ 0x00F8, 0x00FE, 0x00D8 },
	{ 0x01AA, 0x01AB, 0x01AA },
	{ 0x0234, 0x0239, 0x0234 },
	{ 0x023F, 0x0240, 0x2C7E },
	{ 0x0256, 0x0257, 0x0189 },
	{ 0x025D, 0x025F, 0x025D },
	{ 0x026D, 0x026E, 0x026D },
	{ 0x0273, 0x0274, 0x0273 },
	{ 0x0276, 0x027C, 0x0276 },
	{ 0x027E, 0x027F, 0x027E },
	{ 0x0281, 0x0282, 0x0281 },
	{ 0x0284, 0x0286, 0x0284 },
	{ 0x028A, 0x028B, 0x01B1 },
	{ 0x028D, 0x0291, 0x028D },
	{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1FE2 },
	{ 0x1FE6, 0x1FE7, 0x1FE6 },
	{ 0x1FF6, 0x1FF7, 0x1FF6 },
	{ 0x210E, 0x210F, 0x210E },
	{ 0x213C, 0x213D, 0x213C },
	{ 0x2146, 0x2149, 0x2146 },
	{ 0x2C30, 0x2C5E, 0x2C00 },
	{ 0x2C77, 0x2C7B, 0x2C77 },
	{ 0x2D00, 0x2D25, 0x10A0 },
	{ 0xA730, 0xA731, 0xA730 },
	{ 0xA771, 0xA778, 0xA771 },
	{ 0xA794, 0xA795, 0xA794 },
	{ 0xAB30, 0xAB5A, 0xAB30 },
	{ 0xAB64, 0xAB65, 0xAB64 },
	{ 0xFB00, 0xFB06, 0xFB00 },
	{ 0xFB13, 0xFB17, 0xFB13 },
	{ 0xFF41, 0xFF5A, 0xFF21 },
	{ 0x10428, 0x1044F, 0x10400 },
	{ 0x118C0, 0x118DF, 0x118A0 },
	{ 0x1D41A, 0x1D433, 0x1D41A },
	{ 0x1D44E, 0x1D454, 0x1D44E },
	{ 0x1D456, 0x1D467, 0x1D456 },
	{ 0x1D482, 0x1D49B, 0x1D482 },
	{ 0x1D4B6, 0x1D4B9, 0x1D4B6 },
	{ 0x1D4BD, 0x1D4C3, 0x1D4BD },
	{ 0x1D4C5, 0x1D4CF, 0x1D4C5 },
	{ 0x1D4EA, 0x1D503, 0x1D4EA },
	{ 0x1D51E, 0x1D537, 0x1D51E },
	{ 0x1D552, 0x1D56B, 0x1D552 },
	{ 0x1D586, 0x1D59F, 0x1D586 },
	{ 0x1D5BA, 0x1D5D3, 0x1D5BA },
	{ 0x1D5EE, 0x1D607, 0x1D5EE },
	{ 0x1D622, 0x1D63B, 0x1D622 },
	{ 0x1D656, 0x1D66F, 0x1D656 },
	{ 0x1D68A, 0x1D6A5, 0x1D68A },
	{ 0x1D6C2, 0x1D6DA, 0x1D6C2 },
	{ 0x1D6DC, 0x1D6E1, 0x1D6DC },
	{ 0x1D6FC, 0x1D714, 0x1D6FC },
	{ 0x1D716, 0x1D71B, 0x1D716 },
	{ 0x1D736, 0x1D74E, 0x1D736 },
	{ 0x1D750, 0x1D755, 0x1D750 },
	{ 0x1D770, 0x1D788, 0x1D770 },
	{ 0x1D78A, 0x1D78F, 0x1D78A },
	{ 0x1D7AA, 0x1D7C2, 0x1D7AA },
	{ 0x1D7C4, 0x1D7C9, 0x1D7C4 },
};

static Rune lower1[][2] = {
	{ 0x00B5, 0x039C },
	{ 0x00DF, 0x00DF },
	{ 0x00FF, 0x0178 },
	{ 0x0131, 0x0049 },
	{ 0x0138, 0x0138 },
	{ 0x0149, 0x0149 },
	{ 0x017F, 0x0053 },
	{ 0x0180, 0x0243 },
	{ 0x0188, 0x0187 },
	{ 0x018C, 0x018B },
	{ 0x018D, 0x018D },
	{ 0x0192, 0x0191 },
	{ 0x0195, 0x01F6 },
	{ 0x0199, 0x0198 },
	{ 0x019A, 0x023D },
	{ 0x019B, 0x019B },
	{ 0x019E, 0x0220 },
	{ 0x01A8, 0x01A7 },
	{ 0x01AD, 0x01AC },
	{ 0x01B0, 0x01AF },
	{ 0x01B9, 0x01B8 },
	{ 0x01BA, 0x01BA },
	{ 0x01BD, 0x01BC },
	{ 0x01BE, 0x01BE },
	{ 0x01BF, 0x01F7 },
	{ 0x01C6, 0x01C4 },
	{ 0x01C9, 0x01C7 },
	{ 0x01CC, 0x01CA },
	{ 0x01DD, 0x018E },
	{ 0x01F0, 0x01F0 },
	{ 0x01F3, 0x01F1 },
	{ 0x01F5, 0x01F4 },
	{ 0x0221, 0x0221 },
	{ 0x023C, 0x023B },
	{ 0x0242, 0x0241 },
	{ 0x0250, 0x2C6F },
	{ 0x0251, 0x2C6D },
	{ 0x0252, 0x2C70 },
	{ 0x0253, 0x0181 },
	{ 0x0254, 0x0186 },
	{ 0x0255, 0x0255 },
	{ 0x0258, 0x0258 },
	{ 0x0259, 0x018F },
	{ 0x025A, 0x025A },
	{ 0x025B, 0x0190 },
	{ 0x025C, 0xA7AB },
	{ 0x0260, 0x0193 },
	{ 0x0261, 0xA7AC },
	{ 0x0262, 0x0262 },
	{ 0x0263, 0x0194 },
	{ 0x0264, 0x0264 },
	{ 0x0265, 0xA78D },
	{ 0x0266, 0xA7AA },
	{ 0x0267, 0x0267 },
	{ 0x0268, 0x0197 },
	{ 0x0269, 0x0196 },
	{ 0x026A, 0x026A },
	{ 0x026B, 0x2C62 },
	{ 0x026C, 0xA7AD },
	{ 0x026F, 0x019C },
	{ 0x0270, 0x0270 },
	{ 0x0271, 0x2C6E },
	{ 0x0272, 0x019D },
	{ 0x0275, 0x019F },
	{ 0x027D, 0x2C64 },
	{ 0x0280, 0x01A6 },
	{ 0x0283, 0x01A9 },
	{ 0x0287, 0xA7B1 },
	{ 0x0288, 0x01AE },
	{ 0x0289, 0x0244 },
	{ 0x028C, 0x0245 },
	{ 0x0292, 0x01B7 },
	{ 0x0293, 0x0293 },
	{ 0x029E, 0xA7B0 },
	{ 0x0377, 0x0376 },
	{ 0x0390, 0x0390 },
	{ 0x03AC, 0x0386 },
	{ 0x03B0, 0x03B0 },
	{ 0x03C2, 0x03A3 },
	{ 0x03CC, 0x038C },
	{ 0x03D0, 0x0392 },
	{ 0x03D1, 0x0398 },
	{ 0x03D5, 0x03A6 },
	{ 0x03D6, 0x03A0 },
	{ 0x03D7, 0x03CF },
	{ 0x03F0, 0x039A },
	{ 0x03F1, 0x03A1 },
	{ 0x03F2, 0x03F9 },
	{ 0x03F3, 0x037F },
	{ 0x03F5, 0x0395 },
	{ 0x03F8, 0x03F7 },
	{ 0x03FB, 0x03FA },
	{ 0x03FC, 0x03FC },
	{ 0x04CF, 0x04C0 },
	{ 0x0587, 0x0587 },
	{ 0x1D79, 0xA77D },
	{ 0x1D7D, 0x2C63 },
	{ 0x1E9B, 0x1E60 },
	{ 0x1E9F, 0x1E9F },
	{ 0x1F50, 0x1F50 },
	{ 0x1F51, 0x1F59 },
	{ 0x1F52, 0x1F52 },
	{ 0x1F53, 0x1F5B },
	{ 0x1F54, 0x1F54 },
	{ 0x1F55, 0x1F5D },
	{ 0x1F56, 0x1F56 },
	{ 0x1F57, 0x1F5F },
	{ 0x1FB2, 0x1FB2 },
	{ 0x1FB3, 0x1FBC },
	{ 0x1FB4, 0x1FB4 },
	{ 0x1FBE, 0x0399 },
	{ 0x1FC2, 0x1FC2 },
	{ 0x1FC3, 0x1FCC },
	{ 0x1FC4, 0x1FC4 },
	{ 0x1FE5, 0x1FEC },
	{ 0x1FF2, 0x1FF2 },
	{ 0x1FF3, 0x1FFC },
	{ 0x1FF4, 0x1FF4 },
	{ 0x210A, 0x210A },
	{ 0x2113, 0x2113 },
	{ 0x212F, 0x212F },
	{ 0x2134, 0x2134 },
	{ 0x2139, 0x2139 },
	{ 0x214E, 0x2132 },
	{ 0x2184, 0x2183 },
	{ 0x2C61, 0x2C60 },
	{ 0x2C65, 0x023A },
	{ 0x2C66, 0x023E },
	{ 0x2C71, 0x2C71 },
	{ 0x2C73, 0x2C72 },
	{ 0x2C74, 0x2C74 },
	{ 0x2C76, 0x2C75 },
	{ 0x2CE4, 0x2CE4 },
	{ 0x2CF3, 0x2CF2 },
	{ 0x2D27, 0x10C7 },
	{ 0x2D2D, 0x10CD },
	{ 0xA78C, 0xA78B },
	{ 0xA78E, 0xA78E },
	{ 0xA7FA, 0xA7FA },
	{ 0x1D4BB, 0x1D4BB },
	{ 0x1D7CB, 0x1D7CB },
};

int
islowerrune(Rune r)
{
	Rune *match;

	if((match = bsearch(&r, lower4, nelem(lower4), sizeof *lower4, &rune2cmp)))
		return !((r - match[0]) % 2);
	if(bsearch(&r, lower2, nelem(lower2), sizeof *lower2, &rune2cmp))
		return 1;
	if(bsearch(&r, lower1, nelem(lower1), sizeof *lower1, &rune1cmp))
		return 1;
	return 0;
}

int
toupperrune(Rune r)
{
	Rune *match;

	match = bsearch(&r, lower4, nelem(lower4), sizeof *lower4, &rune2cmp);
	if (match)
		return ((r - match[0]) % 2) ? r : r - 1;
	match = bsearch(&r, lower2, nelem(lower2), sizeof *lower2, &rune2cmp);
	if (match)
		return match[2] + (r - match[0]);
	match = bsearch(&r, lower1, nelem(lower1), sizeof *lower1, &rune1cmp);
	if (match)
		return match[1];
	return r;
}
